IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SettingInsert') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SettingInsert]
GO
CREATE PROCEDURE [SettingInsert]
(
    @SettingId int = null output,
    @Key nvarchar(50),
    @Value nvarchar,
    @CreateDate datetime,
    @UpdateDate datetime
)
AS
BEGIN
	SET NOCOUNT ON
	INSERT INTO [Setting](
        [key],
        [value],
        [create_date],
        [update_date]
	)
	VALUES(
        @Key,
        @Value,
        @CreateDate,
        @UpdateDate
	)
	SELECT @SettingId = SCOPE_IDENTITY()
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SettingUpdate') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SettingUpdate]
GO
CREATE PROCEDURE [SettingUpdate]
(
	@SettingId int,
    @Key nvarchar(50),
    @Value nvarchar,
    @CreateDate datetime,
    @UpdateDate datetime
)
AS
BEGIN
	
	UPDATE [Setting]
	SET
        [key]=@Key,
        [value]=@Value,
        [create_date]=@CreateDate,
        [update_date]=@UpdateDate
	WHERE
		[Setting_id] = @SettingId

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SettingDelete') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SettingDelete]
GO
CREATE PROCEDURE [SettingDelete]
(
	@SettingId int	
)
AS
BEGIN
	
	DELETE
	FROM [Setting]
    WHERE
		[Setting_id] = @SettingId
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SettingSelectOne') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SettingSelectOne]
GO
CREATE PROCEDURE [SettingSelectOne]
(
	@SettingId int
)
AS
BEGIN
	SET NOCOUNT ON	
	SELECT
		*
	FROM [Setting] (NOLOCK)
	WHERE
		([Setting_id] = @SettingId)

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SettingSelectAll') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SettingSelectAll]
GO

CREATE PROCEDURE [SettingSelectAll]
AS
BEGIN

	SET NOCOUNT ON
	SELECT
		[Key],
		[Value],
		[setting_id] AS SettingId		
	FROM [Setting] (NOLOCK)

END
GO
